#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <opencv2/opencv.hpp>
#include <vector>
#include "formcamera.h"
#include "dialogconfig.h"
#include "HttpServer.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow, public HttpHandler
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_actionExit_triggered();

    void on_actionConfig_triggered();

    void onClickCamera();

    void onCountResult(int index, int count, int status, bool exception);

    void on_actionStart_triggered();

    void on_actionStop_triggered();

protected:

	virtual void resizeEvent(QResizeEvent *event);

protected:
	void startHttp();
	void stopHttp();
	void broadcast(const std::string& text);
	void setupUri();

	virtual int handleJsonApi(HttpRequest& request, std::string& json);
	virtual void handleUpload(const char* name, const std::string& filepath);
	virtual int handleFileApi(HttpRequest& request, std::string& resp, std::string& mime);
	virtual void handleWebSocketFrame(unsigned char *data, size_t size, unsigned char flags);

	int getCameraList(HttpRequest& request, std::string& jsonText);

	void notifyCameraStatus(int index, bool opened);

private:
    Ui::MainWindow *ui;


private:
    void setupUI();
    void setupMenu();
    void setupCameraForm();

    void startCamera();
    void stopCamera();

	std::string getParamsPath();

    bool isStarted();

private:
    Camera::DeviceList  m_deviceList;
    std::vector< QAction* > m_actionList;

	std::shared_ptr< HttpServer >	m_httpServer;

};

#endif // MAINWINDOW_H
